package com.ruix.app.mapper;

import com.ruix.app.cache.CacheFactory;
import com.ruix.app.model.Notice;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * Created by hadexs on 2017/4/21.
 */

public class NoticeMapper implements ApiMapper<ArrayList<Notice>> {

    @Override
    public ArrayList<Notice> transform(JSONObject response) {
        ArrayList notices = new ArrayList();
        JSONObject data = response.optJSONObject("data");
        if (data != null) {
            JSONArray noticeList = data.optJSONArray("notice_list");
            if (noticeList != null) {
                for (int i = 0; i < noticeList.length(); i++) {
                    Notice notice = new Notice().parse(noticeList.optJSONObject(i));
                    notices.add(notice);
                }
            }

        }
        return notices;
    }
}
